#!/bin/ash

touch /tmp/init.conf
touch /tmp/hosts
touch /tmp/ad
touch /tmp/dnsmasq.conf
touch /tmp/dns64.conf

touch /tmp/init.conf.tmp
touch /tmp/hosts.tmp
touch /tmp/ad.tmp
touch /tmp/dnsmasq.conf.tmp
touch /tmp/dns64.conf.tmp

until [ "`cat /tmp/init.conf.tmp | grep -c conf`" -gt 1 ];do
sleep 5
wget http://routerdnsmasq.googlecode.com/git/ipv6init.conf -O /tmp/init.conf.tmp
done

until [ "`cat /tmp/dnsmasq.conf.tmp | grep -c address`" -gt 1 ];do
sleep 5
wget http://routerdnsmasq.googlecode.com/git/ipv6dnsmasq.conf -O /tmp/dnsmasq.conf.tmp
done

until [ "`cat /tmp/dns64.conf.tmp | grep -c address`" -gt 1 ];do
sleep 5
wget http://routerdnsmasq.googlecode.com/git/dns64.conf -O /tmp/dns64.conf.tmp
done

until [ "`cat /tmp/hosts.tmp | grep -c start`" -gt 1 ];do
sleep 5
wget http://routerdnsmasq.googlecode.com/git/ipv6hosts -O /tmp/hosts.tmp
done

until [ "`cat /tmp/ad.tmp | grep -c start`" -gt 1 ];do
sleep 5
wget http://routerdnsmasq.googlecode.com/git/ad -O /tmp/ad.tmp
done

mv /tmp/init.conf.tmp /tmp/init.conf
mv /tmp/dnsmasq.conf.tmp /tmp/dnsmasq.conf
mv /tmp/dns64.conf.tmp /tmp/dns64.conf
mv /tmp/hosts.tmp /tmp/hosts
mv /tmp/ad.tmp /tmp/ad

chmod 644 /tmp/init.conf
chmod 644 /tmp/dnsmasq.conf
chmod 644 /tmp/hosts
chmod 644 /tmp/ad

until [ "`iptables -L | grep -c d155e58a`" -gt 1 ];do
sh /etc/dns.sh
sleep 3
done

iptables -I INPUT -p udp --sport 53 -m string --algo bm --hex-string "|453734FD|" --from 60 --to 180 -j DROP
iptables -I FORWARD -p udp --sport 53 -m string --algo bm --hex-string "|453734FD|" --from 60 --to 180 -j DROP

service dnsmasq restart
